<?php
$xtpl = new XTemplate("modules/home/pages_task.htm");
$UPLOAD = new UPLOAD();
//--
//--
$cidsub=intval($_GET['cidsub']);
//--
//--
$POST = $_POST;
if($_POST[type] == 'NEW'){	

	$POST['image'] = $UPLOAD->doUploadImage("upload/image/", 'image', '', '150', '');
	
	$POST['date'] = date("Y-m-d");
	$POST[name]=addslashes($POST[name]);
	$POST[content]= addslashes($POST[content]);
	//--
	$DB->DBInsert('pages', $POST);
	//--
	$GUI->redir("?mod=home&catepath=".$_GET[catepath]."&act=pages&cidsub=".$cidsub."");
}
//--
//--
//--
//--
elseif($_POST[type] == 'EDIT'){
	if($_FILES['image']['name'] !=''){
	 $POST['image'] = $UPLOAD->doUploadImage("upload/image/", 'image', '', '150', '');
	}
	$POST['date'] = date("Y-m-d");
	$POST['status']=$_POST['status'];
	$POST[name]=addslashes($POST[name]);
	$POST[content]= addslashes($POST[content]);
	//--
	$DB->DBUpdate('pages',$POST, "WHERE page_id = '".$_POST[id]."'");
	//--
	//-- check image
	if($POST['delete_img'] == '1'){
	// delete_img at root
		$row = $DB->FetchData('pages','*',"WHERE page_id='".$_POST[id]."'");	
		@unlink("../upload/image/thumb".$row['image']);
	// end	
		$sql_up="UPDATE {$DP}pages SET image='' WHERE page_id =".$_POST[id]."";
		mysql_query($sql_up);
	}
	//-- end
	$GUI->redir("?mod=home&catepath=".$_GET[catepath]."&act=pages&cidsub=".$cidsub."");
}
//--
//--
if($_GET[id] != ''){
	$row = $DB->FetchData('pages','*',"WHERE page_id='".$_GET[id]."'");
	$row[name]=stripslashes($row[name]);
	$row[type] = 'EDIT';
	if($row['image']!==''){	
		$row['show_image']='<img src="../upload/image/thumb'.$row['image'].'" border="0" width="65">';
	}
	if($row['status']=='1'){
 		$row['status']="checked";
	}
		
}else{
	$row[type] = 'NEW';
	$row[cate_id] =$_GET['cidsub'];
	
	$row['status']="checked";
	
	//--
	
}
//--
$_FCKeditor = new FCKeditor("content");
$_FCKeditor->BasePath = $siteFCKeditorPath;
$_FCKeditor->Width = '95%';
$_FCKeditor->Height = '500';
$_FCKeditor->Value = stripslashes($row[content]);
//--
//$row[name]=stripslashes($row[name]);
$xtpl->assign("write",$row);
//--
//--
//--
//--
//--
//--
$waypathlink = '&raquo;&nbsp;<a href="?mod=home&catepath='.$_GET[catepath].'&act=pages" class="waypath">Pages Management</a>:&nbsp;'.$row[type];
$xtpl_main->assign("waypathlink",$waypathlink);
//--
//--
//--
//--
//--
//--
$save_button = $GUI->button_ren("Save","javascript: doSavepages();");
$xtpl->assign("save_button",$save_button);
//--
$cancel_button = $GUI->button_ren("Cancel","javascript: add('?mod=home&catepath=".$_GET[catepath]."&act=pages&cidsub=".$cidsub."');");
$xtpl->assign("cancel_button",$cancel_button);
//--
//--
//--
//--
//--
//--
?>